﻿// -----------------------------------------------------------------------
// <copyright file="TabMasksLoader.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.Controls.ExtendedTabControl
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public static class TabMasksLoader
    {
        public static UserControl Parent;

        public static List<string> TabbedMasks = new List<string>();
        public static List<string> MasksNames = new List<string>();

        public static void ShowTab(int index)
        {
            foreach (Control control in Parent.Controls["MaskContainer"].Controls)
            {
                control.Visible = false;
            }

            // Get namespace and class name
            string classPath = TabMasksLoader.TabbedMasks[index];
            string[] classURI = classPath.Split(';');

            if (classURI[2] == "false")
            {
                // Get mask
                System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(classURI[0]);
                Type t = assembly.GetType(classURI[1]);
                UserControl skinableMask = (UserControl)Activator.CreateInstance(t);
                skinableMask.Dock = DockStyle.Fill;

                // Add mask to this tab
                Parent.Controls["MaskContainer"].Controls.Add(skinableMask);
                TabbedMasks[index] = classPath.Replace(";false", ";true");

                if (!MasksNames.Contains(skinableMask.Name))
                {
                    MasksNames[index] = skinableMask.Name;
                }
            }
            else
            {
                Parent.Controls["MaskContainer"].Controls[MasksNames[index]].Visible = true;
            }
        }
    }
}
